package com.hgc.ch04.aqs;

/**
 * Created by 01367627 on 2019/7/11.
 */
public class TestMylock {

    private static MyLock lock = new MyLock();

    private static class MyThread extends Thread {
        private String name;

        public MyThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            lock.lock();
            try {
                System.out.println(getName() + "take the lock!");
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                System.out.println(getName() + "release the lock!");
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new MyThread("t" + i).start();
        }
    }

}
